Skip to main content

Switch

A common component for the react native switch component

NameTypeDefault ValueRequiredDescription
accessiblebooleanNoWhen true, indicates that the view is an accessibility element. By default, all the touchable elements are accessible.
accessibilityActionsreadonly Readonly<{ name: string; label?: string; }>[]NoProvides an array of custom actions available for accessibility.
accessibilityLabelstringNoOverrides the text that's read by the screen reader when the user interacts with the element. By default, the label is constructed by traversing all the children and accumulating all the Text nodes separated by space.
aria-labelstringNoAlias for accessibilityLabel https://reactnative.dev/docs/view#accessibilitylabel https://github.com/facebook/react-native/issues/34424
accessibilityRoleAccessibilityRoleNoAccessibility Role tells a person using either VoiceOver on iOS or TalkBack on Android the type of element that is focused on.
accessibilityStateAccessibilityStateNoAccessibility State tells a person using either VoiceOver on iOS or TalkBack on Android the state of the element currently focused on.
aria-busybooleanNoalias for accessibilityState see https://reactnative.dev/docs/accessibility#accessibilitystate
aria-checkedboolean | "mixed"No
aria-disabledbooleanNo
aria-expandedbooleanNo
aria-selectedbooleanNo
accessibilityHintstringNoAn accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not obvious from the accessibility label.
accessibilityValueAccessibilityValueNoRepresents the current value of a component. It can be a textual description of a component's value, or for range-based components, such as sliders and progress bars, it contains range information (minimum, current, and maximum).
aria-valuemaxnumberNo
aria-valueminnumberNo
aria-valuenownumberNo
aria-valuetextstringNo
onAccessibilityAction(event: AccessibilityActionEvent) => voidNoWhen `accessible` is true, the system will try to invoke this function when the user performs an accessibility custom action.
importantForAccessibility"auto" | "yes" | "no" | "no-hide-descendants"No[Android] Controlling if a view fires accessibility events and if it is reported to accessibility services.
aria-hiddenbooleanNoA value indicating whether the accessibility elements contained within this accessibility element are hidden.
aria-modalbooleanNo
roleRoleNoIndicates to accessibility services to treat UI component like a specific role.
accessibilityLabelledBystring | string[]NoIdentifies the element that labels the element it is applied to. When the assistive technology focuses on the component with this props, the text is read aloud. The value should should match the nativeID of the related element. @platform android
aria-labelledbystringNoIdentifies the element that labels the element it is applied to. When the assistive technology focuses on the component with this props, the text is read aloud. The value should should match the nativeID of the related element. @platform android
accessibilityLiveRegion"none" | "polite" | "assertive"NoIndicates to accessibility services whether the user should be notified when this view changes. Works for Android API >= 19 only. @platform android See https://reactnative.dev/docs/view#accessibilityliveregion
aria-live"polite" | "assertive" | "off"NoIndicates to accessibility services whether the user should be notified when this view changes. Works for Android API >= 19 only. @platform android See https://reactnative.dev/docs/view#accessibilityliveregion
accessibilityElementsHiddenbooleanNoA Boolean value indicating whether the accessibility elements contained within this accessibility element are hidden to the screen reader. @platform ios
accessibilityViewIsModalbooleanNoA Boolean value indicating whether VoiceOver should ignore the elements within views that are siblings of the receiver. @platform ios
onAccessibilityEscape() => voidNoWhen accessible is true, the system will invoke this function when the user performs the escape gesture (scrub with two fingers). @platform ios
onAccessibilityTap() => voidNoWhen `accessible` is true, the system will try to invoke this function when the user performs accessibility tap gesture. @platform ios
onMagicTap() => voidNoWhen accessible is true, the system will invoke this function when the user performs the magic tap gesture. @platform ios
accessibilityIgnoresInvertColorsbooleanNohttps://reactnative.dev/docs/accessibility#accessibilityignoresinvertcolorsios @platform ios
accessibilityLanguagestringNoBy using the accessibilityLanguage property, the screen reader will understand which language to use while reading the element's label, value and hint. The provided string value must follow the BCP 47 specification (https://www.rfc-editor.org/info/bcp47). https://reactnative.dev/docs/accessibility#accessibilitylanguage-ios @platform ios
onPress(value: boolean) => voidYescallback called on value change of the switch
onbooleanNooptional value of switch, updated with onPress
testIDstringNooptional testID of switch
a11yHintstringNooptional accessibilityHint